<template>
	<view class="work-index">
		<view :class="positionids.indexOf(item.id)>-1?'worklistChange':'worklist'"  v-for="(item,index) in workList" :key="index" @click="jump(item.id)">
			<view class="position">
					{{item.title}}
			</view>
			<view class="salary">
				<view class="title">
					{{item.stitle}}
				</view>
				<view class="secondary" v-if="item.secondary=='1'">
					兼职
				</view>
			</view>
			<view class="tag">
				<view class="tag-item">
					<image src="/static/work/pio_1.png"></image>
					<text class="text" >{{item.areas.title?item.areas.title:item.areas}}</text>
				</view>
				<view class="tag-item">
					<image src="/static/work/pio_2.png"></image>
					<text class="text">{{item.age.title?item.age.title:item.age}}</text>
				</view>
			</view>
			<view class="address">
				<view class="name">
					{{item.company.name?item.company.name:item.company}}
				</view>
				<view class="time">
					{{item.date}}
				</view>
			</view>
		</view>
		<empty v-if="total==0" :text='text' :Height="Heights"/>
		<uni-load-more :status="status" v-if="status"></uni-load-more>
		<uni-popup ref="popup" type="center">
			<view class="tips">
				<view class="title">
					提示
				</view>
				<view class="value">
					今天查看需求上限，分享给朋友可增加{{resume_forward}}次查看机会
				</view>
				<view class="share-box">
					<view class="close" @click="close()">
						取消
					</view>
					<view class="goshare">
						去分享
						<button open-type="share" class="bnt" @click="shareClose()"></button>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	import * as user from '@/api/user.js'
	import empty from '@/components/empty/index.vue'
	export default {
		props: {
			workList: Array,
			total:Number,
			userInfos:Object,
			Type:Number,
			text:String,
			status:String,
			Heights:Number
		},
		components:{
			empty
		},
		name: "work",
		data() {
			return {
				title: '', //分享标题
				imgage: '', //分享图片
				resume_forward: '', //增加次数
				userInfo:this.userInfos,
				positionids:[]
			};
		},
		onShareAppMessage(res) {

			return {
				title: this.title, //分享标题
				imageUrl: this.imgage,
				path: '/pages/home/index'
			}
		},
		created() {
			// 获取分享信息
			this.nameGetConfig()
		},
		mounted(){
			// uni.$on('userin',(data=>{
			// 	this.positionids = data.positionids.map(Number)||[]
			// }))
			if(uni.getStorageSync('token')){
				user.getUserInfo({type:uni.getStorageSync('Type')}).then(res=>{
					this.userInfo = res.data
					this.positionids = res.data.positionids.map(Number)
				})
			}
			
		},
		methods:{
			// 获取分享图片
			nameGetConfig() {
				index.nameGetConfig({name:'wx_share_image,resume_forward'}).then(res=>{
					this.imgage = res.data.wx_share_image
					this.title = res.data.wx_share_title
					this.resume_forward = res.data.resume_forward
				})
			},
			jump(id){
					user.getUserInfo({type:uni.getStorageSync('Type')}).then(res=>{
						this.userInfo = res.data
						if(res.data.visual_upper_limit<=res.data.resume_position&&res.data.positionids.map(Number).indexOf(id)<0){
							this.$refs.popup.open()
						}
						else{
							this.positionids.push(id)
							this.$tools.navigate(`/pages/home/jobDetails/index?position_id=${id}`)
						}
					})
			},
			close(){
				this.$refs.popup.close()
			},
			// 去分享记录下方便提示
			shareClose() {
				this.$refs.popup.close()
				uni.setStorageSync('shareType', '1');
				// #ifdef APP-PLUS
				uni.share({
				    provider: 'weixin',
				    scene: "WXSceneSession",
				    type: 5,
				    // imageUrl: this.share.image,
				    imageUrl: 'https://xczp.wanhedashuju.com/uploads/20220107/125c54dad49a1c68b2796dd71128f698.png',
				    title: '县城直聘',
				    miniProgram: { 
				        id: 'gh_6b4bd9a933d2',
				        path: '/pages/home/index',
				        type: 0,
				        webUrl: 'https://app.wanhedashuju.com/'
				    },
				    success: ret => {
						user.wxForwardGetAward({
							type: 0
						}).then(res => {
							// 关闭弹窗
						})
				        console.log(JSON.stringify(ret));
				    }
				});
				// #endif
			}
		}
	}
</script>

<style lang="scss">
	.work-index {
		padding: 5rpx 20rpx;
		padding-bottom: 40rpx;
		.worklist {
			background: #ffffff;
			padding: 28rpx 30rpx;
			margin-bottom: 12rpx;
			z-index: 1;
			.position {
				font-size: 32rpx;
				font-weight: 700;
				color: #333333;
				line-height: 45rpx;
				
			}

			.salary {
				font-size: 32rpx;
				font-weight: 600;
				color: #F24C19;
				line-height: 45rpx;
				margin-top: 12rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.secondary{
					font-size: 24rpx;
					padding: 0rpx 32rpx;
					border: 1px solid #Ff6600;
					border-radius: 5px;
					color: #Ff6600
				}
			}

			.tag {
				display: flex;
				align-items: center;
				margin-top: 12rpx;

				.tag-item {
					display: flex;
					align-items: center;
					margin-right: 30rpx;
					color: #666;
					// letter-spacing: -0.52px;
					font-size: 26rpx;
					image {
						width: 30rpx;
						height: 30rpx;
					}

					.text {
						margin-left: 5px;
						font-size: 26rpx;
						color: #666;
						letter-spacing: -0.52px;
					}
				}

			}

			.address {
				display: flex;
				justify-content: space-between;
				margin-top: 12rpx;

				.name {
					font-size: 24rpx;
					font-weight: 400;
					color: #666666;
				}

				.time {
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;
				}
			}
		}
		.worklistChange {
			background: #ffffff;
			padding: 28rpx 30rpx;
			margin-bottom: 12rpx;
			z-index: 1;
			.position {
				font-size: 32rpx;
				font-weight: 700;
				color: #aaaaaa;
				line-height: 45rpx;
				
			}
		
			.salary {
				font-size: 32rpx;
				font-weight: 600;
				color: #F24C19;
				line-height: 45rpx;
				margin-top: 12rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.secondary{
					font-size: 24rpx;
					padding: 0rpx 32rpx;
					border: 1px solid #Ff6600;
					border-radius: 5px;
					color: #Ff6600
				}
			}
		
			.tag {
				display: flex;
				align-items: center;
				margin-top: 12rpx;
		
				.tag-item {
					display: flex;
					align-items: center;
					margin-right: 30rpx;
					// letter-spacing: -0.52px;
					font-size: 26rpx;
					image {
						width: 30rpx;
						height: 30rpx;
					}

					.text {
						margin-left: 5px;
						font-size: 26rpx;
						color: #aaaaaa;
						letter-spacing: -0.52px;
					}
				}
		
			}
		
			.address {
				display: flex;
				justify-content: space-between;
				margin-top: 12rpx;
		
				.name {
					font-size: 24rpx;
					font-weight: 400;
					color: #aaaaaa;
				}
		
				.time {
					font-size: 24rpx;
					font-weight: 400;
					color: #aaaaaa;
				}
			}
		}
		.tips{
			width: calc(100vw - 190rpx);
			background: #ffffff;
			border-radius: 16rpx;
			.title{
				font-size: 36rpx;
				font-weight: 700;
				color: #202020;
				line-height: 54rpx;
				padding: 40rpx 40rpx 16rpx;
			}
			.value{
				margin-top: 16rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #202020;
				padding: 0rpx 40rpx 40rpx;
			}
			.share-box{
				display: flex;
				justify-content: space-between;
				border-top: 2rpx solid rgba(196,196,196,0.2);;
				.close{
					width: 50%;
					text-align: center;
					padding: 40rpx 0;
					border-right: 2rpx solid rgba(196,196,196,0.2);;
					font-size: 32rpx;
					font-weight: 400;
					color: #202020;
				}
				.goshare{
					width: 50%;
					text-align: center;
					padding: 40rpx 0;
					font-size: 32rpx;
					font-weight: 700;
					color: #FF6600;
					position: relative;
					button::after{
					 	border: none;
					}
					.bnt {
						position: absolute;
						width: 100%;
						height: 100%;
						top: 0;
						left: 0;
						opacity: 0;
						z-index: 999;
					}
				}
			}
		}

	}
</style>
